package com.example.demo.design.singleton;

/**
 * @Author: liull
 * @Description:
 * @Date: Created in 10:04 2021/4/9
 * @Modified By:
 */
public class Client {

    public static void main(String[] args) {
        // LoadBalancer balancer1 = LoadBalancer.getLoadBalancer();
        // LoadBalancer balancer2 = LoadBalancer.getLoadBalancer();
        // LoadBalancer balancer3 = LoadBalancer.getLoadBalancer();
        // LoadBalancer balancer4 = LoadBalancer.getLoadBalancer();
        // // 判断服务器负载均衡器是否相同
        // if (balancer1 == balancer2 && balancer2 == balancer3 && balancer3 == balancer4) {
        // System.out.println("服务器负载均衡器具有唯一性！");
        // }
        // // 增加服务器
        // balancer1.addServer("Server 1");
        // balancer1.addServer("Server 2");
        // balancer1.addServer("Server 3");
        // balancer1.addServer("Server 4");
        // // 模拟客户端请求的分发
        // for (int i = 0; i < 10; i++) {
        // String server = balancer1.getServer();
        // System.out.println("分发请求至服务器： " + server);
        // }

        Singleton balancer1 = Singleton.getInstance();
        Singleton balancer2 = Singleton.getInstance();
        Singleton balancer3 = Singleton.getInstance();
        Singleton balancer4 = Singleton.getInstance();
        // 判断服务器负载均衡器是否相同
        if (balancer1 == balancer2 && balancer2 == balancer3 && balancer3 == balancer4) {
            System.out.println("服务器负载均衡器具有唯一性！");
        }

    }
}
